﻿using System;
using HiTeachers.Entities;
using HiTeachers.Services;

namespace HiTeachers.Web.Admin
{
    public partial class TitlePageMngt : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack) return;

            Page.CloseMessage(lblMsg);
            BindingTitle();
        }

        protected void DdlTitlePageSelectedIndexChanged(object sender, EventArgs e)
        {
            BindingTitle();
            Page.CloseMessage(lblMsg);
        }

        protected void BtnUpdateClick(object sender, EventArgs e)
        {
            SiteConfig siteConfig = SiteConfigServices.GetByTextKey(ddlTitlePage.SelectedValue);
            if (siteConfig == null)
                siteConfig = new SiteConfig
                                 {
                                     TextKey = ddlTitlePage.SelectedValue,
                                     Value = txtValue.Text
                                 };
            else
                siteConfig.Value = txtValue.Text;

            SiteConfigServices.SaveOrUpdate(siteConfig);
            Page.DisplayMessage(lblMsg, "Cập nhật thành công!", MessageType.Success);
        }

        protected void BtnCancelClick(object sender, EventArgs e)
        {

        }

        private void BindingTitle()
        {
            SiteConfig siteConfig = SiteConfigServices.GetByTextKey(ddlTitlePage.SelectedValue);
            txtValue.Text = siteConfig == null ? string.Empty : siteConfig.Value;
        }
    }
}
